import json

from work_zykj.oracle.oracle_util import oracle_util_class

# 338328 【功能反馈】6846-陈羊清-母猪不能淘汰
if __name__ == '__main__':
    # 查找有问题的采购单据
    sql = "select * from fr_trn_purchase_detail d where d.org_code = '130422015' and  document_no in ('4115200000038', '4115200000039', '4115200000042', '4115200000044')"
    oracle_util = oracle_util_class()
    rs = oracle_util.select(sql, 'NMDCFARM')
    rs = json.loads(rs)
    for d in rs:
        document_no = d['DOCUMENT_NO']
        qty = d['PUR_QTY']
        female_qty = d['PUR_FEMALE_QTY']
        male_qty = d['PUR_MALE_QTY']
        product_spec = str(d['PRODUCT_SPEC'])
        swine_track = product_spec.split("#")[1]
        org_code = d['ORG_CODE']
        print(f'--{swine_track}')
        sql = "select * from fr_ms_trn_breeder b where b.org_code = '{}' and  b.product_spec like '%{}%';".format(
            org_code, swine_track)
        print('--' + sql)
        sex = swine_track.split("-")[1]
        if '1' == sex:
            male_qty = qty
        else:
            female_qty = qty
        sql = "update fr_trn_purchase_detail set PUR_FEMALE_QTY = '{}' , PUR_MALE_QTY = {},last_user_id = 'yjz20250822'  where org_code = '{}' and document_no = '{}';".format(
            female_qty, male_qty, org_code, document_no
        )
        print(sql)

        sql = "update fr_ms_trn_breeder set FEMALE_QTY = '{}' , MALE_QTY = {},last_user_id = 'yjz20250822' where org_code = '{}' and  product_spec like '%{}%';".format(
            female_qty, male_qty, org_code, swine_track
        )
        print(sql, '\n')
